package com.hotelmanage.hm.serviceImpl;

import com.hotelmanage.hm.mapper.OrderMapper;
import com.hotelmanage.hm.po.OrderPO;
import com.hotelmanage.hm.po.OrderPOExample;
import com.hotelmanage.hm.service.OrderService;
import com.hotelmanage.hm.vo.OrderVO;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public int newOrder(OrderVO orderVO) {

        OrderPO orderPO = new OrderPO();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        orderPO.setChild(orderVO.getChild());
        try {
            orderPO.setIntime(sdf.parse(orderVO.getIntime()));
            orderPO.setOuttime(sdf.parse(orderVO.getOuttime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        orderPO.setNum(orderVO.getNum());
        orderPO.setUserid(orderVO.getUserid());
        orderPO.setRoomid(orderVO.getRoomid());
        orderPO.setPeople(orderVO.getPeople());
        orderPO.setState(1);
        return orderMapper.insertSelective(orderPO);


    }

    @Override
    public List<OrderPO> getByUserid(Integer userId) {
        OrderPOExample orderPOExample = new OrderPOExample();
        orderPOExample.or().andUseridEqualTo(userId);
        return orderMapper.selectByExample(orderPOExample);
    }

    @Override
    public List<OrderPO> getOrders() {
        OrderPOExample orderPOExample = new OrderPOExample();
        return orderMapper.selectByExample(orderPOExample);
    }

    @Override
    public int deleteOrder(Integer orderId) {
        return orderMapper.deleteByPrimaryKey(orderId);
    }


}
